#ifndef _ROUTER_SERVICE_H_
#define _ROUTER_SERVICE_H_
#include "router_service.h"
#endif


#define bool	int
#define false	0
#define true	1
#define normalBufferSize 1000
#define sendBufferSize 100
#define SendNumberOfEDP 5
#define p_buffer_size 20

#define DEBUG_WM
#define TEST_SOCKET
//#define TEST_TOKEN


//socket connecti
#define NUMBEROFMEMBER 3





bool f_token_thread = false;
bool f_init_once = false;
int i_normalBuffer_idx;
int i_sendBuffer_idx;
// i_normalBuffer_idx points out the last idx on a_normalBuffer

int get_sendNumber_of_edp();
void send_sendBufferedEDP(router_t *p_router, int i_size);
void set_participant_tag();
void set_nextTx_tag();
void set_seq_tag();
void set_order_tag();
int get_nextTx_tag(int i_idx);
int get_participant_tag(int i_idx);
void get_seq_tag();
void set_normalBuffer(char *p_data, int i_size);
void set_weight();
void buffering_for_system(router_t* p_router, char *p_buffer, int i_size);
void ErrorHandling(char *message);
int set_tag(boolean participant, boolean seq, boolean nextTx, boolean order);
void init_normalBuffer_tag_field(int i_start);
void set_edp_to_sendBuffer(int i_sendNumber, router_t *p_router, int i_size);
void update_normalBuffer(int i_sendNumber, int i_size);
UINT WINAPI check_token(void *arg);
void update_sendBuffer(int cnt);

// socoket connection 
void SetServAddrOfOthers();
UINT WINAPI set_communication(void *arg);
void set_info();
DWORD WINAPI SetConnection();
DWORD WINAPI clnt_socket_recv();

// 
void quickSort(int left, int right);
void seq_quickSort(int left, int right);
int partition(int left, int right);
int seq_partition(int left, int right);
void swap_t(int i, int ii);

//Zento
void send_to_remote_best_client(router_t *p_router, char *p_buffer, int i_size);

typedef struct EDPTag{
	int iOrderTag;
	int iParticipantTag;	//	GuidPrefix_t guid_prefix;
	int iNextTxTag;
	//int iIsHere;
	int iTotal;


	int iSeq;	//	same as the normal buffer's idx 
				//  if iTotal val is same to other, it can be used for ordering
}EDPTag;

typedef struct EDPInfo{
	//data_t a_data;
	char *p_data;
	EDPTag a_Tag;
}EDPinfo;